
<?php Yii::app()->clientScript->registerCssFile('css/InvoiceReport.css');?>
<?php Yii::app()->clientScript->registerCssFile('css/ContractReport.css');?>

<div id="invoice-report">
    <div id="create-date">
        <?php echo date('Y-m-d'); ?>
        <br/>
        <?php echo date('H:i:s'); ?>
    </div>

    <div id="title">
        Contract by Sales Person Report
    </div>
    <div class="details">
        <div class="start-date">Start Date <?php echo $model->startDate; ?></div>
        <div class="end-date">End Date <?php echo $model->endDate; ?></div>
        <div class="type">Contract Status <?php echo $model->status==''?'All':  ContractStatus::getText($model->status); ?></div>
        <div class="type">Contract Type <?php echo $model->type==''?'All': ContractType::getText($model->type); ?></div>
        <div class="type">Sales Person <?php echo $model->empno==''?'All': Employees::getEmployeeName($model->empno); ?></div>
    </div>
    <div id="content">
        <?php 
        $table=new CI_Table();
        $table->set_template(array(
            'table_open'=>'<table class="zeebra">'
        ));
        
        $data=$model->getData();
        $count=0;
        foreach($data as $yearText=>$year){
            foreach($year as $monthText=>$month){
                echo CHtml::tag('div',array('class'=>'monthText'),$monthText.' '.$yearText);
                echo CHtml::tag('div',array('class'=>'month'),NULL,false);
                
                    foreach($month as $empno=>$salesPerson){
                        echo CHtml::tag('div',array('class'=>'salesPersonName'),Employees::getEmployeeName($empno));
                        echo CHtml::tag('div',array('class'=>'salesperson'),NULL,false);
                        $total=0;
                        $table->set_heading('Type','No.','Location Name','Amount');
                        foreach($salesPerson as $contract){
                            /* @var $contract Contracts */
                            $location=$contract->location;
                            $table->add_row(
                                ContractType::getText($contract->contractype),
                                $contract->contractid,
                                $location!=NULL?$location->locname.'<br/>'.$location->add1:'',
                                array('data'=>$contract->contractamount,'class'=>'money')    
                                );
                            $total+=$contract->contractamount;
                            $count++;
                        }
                        $table->add_row('Total','&nbsp','&nbsp',  array('data'=>number_format($total,2),'class'=>'money'));
                        echo $table->generate();
                        $table->clear();
                        echo CHtml::closeTag('div');
                        
                    }
                    echo CHtml::closeTag('div');
                    
                    
            }
        }
        
        ?>
       
    </div>
    
  
</div>